package com.leetcode;

import java.util.Arrays;

/**
 * 467. 环绕字符串中唯一的子字符串
 * 2022-05-25 每日一题
 *
 * @author fy
 * @date 2022/5/25 8:12
 */
public class Solution467 {

    public int findSubstringInWraproundString(String p) {
        int[] dp = new int[26];
        int k = 0;
        for (int i = 0; i < p.length(); ++i) {
            // 字符之差为 1 或 -25
            if (i > 0 && (p.charAt(i) - p.charAt(i - 1) + 26) % 26 == 1) {
                ++k;
            } else {
                k = 1;
            }
            dp[p.charAt(i) - 'a'] = Math.max(dp[p.charAt(i) - 'a'], k);
        }
        return Arrays.stream(dp).sum();
    }

    public static void main(String[] args) {
        String p = "zab";
        int res = new Solution467().findSubstringInWraproundString(p);
        System.out.println(res);
    }

}
